//
//  BGNewFeatureViewController.m
//  bigMall
//
//  Created by LTOVE on 16/7/5.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGNewFeatureViewController.h"
#import "BGNewfeatureViewCell.h"

#define BGNewFeatureCount 3

@interface BGNewFeatureViewController ()

@property (nonatomic, weak) UIPageControl *pageControl;

@end

@implementation BGNewFeatureViewController

static NSString * const reuseIdentifier = @"Cell";


- (instancetype)init
{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0;
    
    return [self initWithCollectionViewLayout:layout];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 取消滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;
    
    // 添加padgeController
    [self setUpPadgeController];
    
}

- (void)setUpPadgeController
{
    
    UIPageControl *page = [[UIPageControl alloc] init];
    
    page.center = CGPointMake(self.view.center.x, self.view.height*0.96);
    page.numberOfPages = BGNewFeatureCount;
    page.backgroundColor = [UIColor redColor];
    page.currentPageIndicatorTintColor = [UIColor orangeColor];
    
    page.pageIndicatorTintColor = [UIColor whiteColor];
    _pageControl = page;
    [self.view addSubview:page];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger page = scrollView.contentOffset.x / scrollView.width + 0.5;
    
    _pageControl.currentPage = page;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return BGNewFeatureCount;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    // 创建cell
    BGNewfeatureViewCell *cell = [BGNewfeatureViewCell cellWithCollectionView:collectionView indexPath:indexPath];
    
    // Configure the cell
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%ld",indexPath.row + 1];
    
#ifndef __IPHONE_8_0 // xcode6就不需要编译
    if (inch4) {
        imageName = [imageName stringByAppendingString:@"-568h"];
    }
#endif
    
    cell.imageName = imageName;
    
    [cell setIndexPath:indexPath pagecount:BGNewFeatureCount];
    
    return cell;
}
@end
